package astoliarskyi.wicket.card.restriction;

import astoliarskyi.wicket.CoreSystem;
import java.math.BigDecimal;
import java.util.Calendar;

public class Accumulator extends RestrictionContainer {

	private BigDecimal moneyLeft = BigDecimal.ZERO;
	
	@Override
	public boolean checkout(Calendar dateToday) {
		BigDecimal tripPrice = CoreSystem.INSTANCE.getTripPrice();
		if (moneyLeft.compareTo(tripPrice) >= 0) {
			moneyLeft = moneyLeft.subtract(tripPrice);
			return true;
		} else {
			return false;
		}
	}

	@Override
	public void rechargeBy(BigDecimal rechargeAmount) {
		moneyLeft = moneyLeft.add(rechargeAmount);
	}

	@Override
	public BigDecimal getMoneyLeft(){
		return moneyLeft;
	}
	
	@Override
	public Term.TermType getTermType() {
		return Term.TermType.NO_TERM;
	}

	@Override
	public int getTripsLeft() {
		int tripsLeft = moneyLeft.divide(CoreSystem.INSTANCE.getTripPrice()).intValue();
		return tripsLeft;
	}
}
